*use "C:\...\AFD_Data_20_stm_13_07_22.dta", clear


*generate eventdate = dofc(date)
*format eventdate %td
*drop date
*rename eventdate date

gen year = year(date)
tab year

rename date date_

display date("2017-09-24", "YMD")
display date("2017-10-01", "YMD")
display date("2016-03-13", "YMD")
display date("2016-03-20", "YMD")


* Identifying election dates
*BTW 2017
gen postelectiondate = 0
replace postelectiondate = 1 if date_ >=21086 & date_<=21093
*LTW BW, RP and SAH 2016
replace postelectiondate = 1 if date_ >=20526 & date_<=20533
* Bayern 2018
display date("2018-10-14", "YMD")
replace postelectiondate = 1 if date_ >=21471 & date_<=21478
* Berlin 2016
display date("2017-05-07", "YMD")
replace postelectiondate = 1 if date_ >=20715 & date_<=20722
* Brandenburg 2014, 2019
display date("2014-09-14", "YMD")
replace postelectiondate = 1 if date_ >=19980 & date_<=19987
display date("2019-09-01", "YMD")
replace postelectiondate = 1 if date_ >=21793 & date_<=21800
* Bremen 2015, 2019
display date("2015-05-10", "YMD")
replace postelectiondate = 1 if date_ >=20218 & date_<=20225
display date("2019-05-26", "YMD")
replace postelectiondate = 1 if date_ >=21695 & date_<=21702
* Hamburg 2015, 2020
display date("2015-02-15", "YMD")
replace postelectiondate = 1 if date_ >=20134 & date_<=20141
display date("2020-02-23", "YMD")
replace postelectiondate = 1 if date_ >=21968 & date_<=21975
* Hessen 2018
display date("2018-10-28", "YMD")
replace postelectiondate = 1 if date_ >=21485 & date_<=21492
* MVP 2016
display date("2016-09-04", "YMD")
replace postelectiondate = 1 if date_ >=20701 & date_<=20708
* Niedersachsen 2017
display date("2017-10-15", "YMD")
replace postelectiondate = 1 if date_ >=21107 & date_<=21114
* NRW 2017
display date("2017-05-14", "YMD")
replace postelectiondate = 1 if date_ >=20953 & date_<=20960
* Saar 2017
display date("2017-03-26", "YMD")
replace postelectiondate = 1 if date_ >=20904 & date_<=20911
* Sachsen 2014, 2019
display date("2014-08-31", "YMD")
replace postelectiondate = 1 if date_ >=19966 & date_<=19973
display date("2019-09-01", "YMD")
replace postelectiondate = 1 if date_ >=21793 & date_<=21800
* Schleswig-Holstein 2017
display date("2017-05-07", "YMD")
replace postelectiondate = 1 if date_ >=20946 & date_<=20953
* Thüringen 2014, 2019
display date("2014-09-14", "YMD")
replace postelectiondate = 1 if date_ >=19980 & date_<=19987
display date("2019-10-27", "YMD")
replace postelectiondate = 1 if date_ >=21849 & date_<=21856

* Identifying AfD convention dates: convention dates +/- one day

gen conventiondate = 0
display date("2013-04-14", "YMD")
replace conventiondate = 1  if date_ >=19461 & date_<=19463
display date("2014-01-25", "YMD")
replace conventiondate = 1  if date_ >=19747 & date_<=19749
display date("2014-03-22", "YMD")
replace conventiondate = 1  if date_ >=19803 & date_<=19805
display date("2015-01-30", "YMD")
replace conventiondate = 1  if date_ >=20117 & date_<=20122
display date("2015-07-04", "YMD")
replace conventiondate = 1  if date_ >=20272 & date_<=20276
display date("2015-11-28", "YMD")
replace conventiondate = 1  if date_ >=20419 & date_<=20423
display date("2015-11-28", "YMD")
replace conventiondate = 1  if date_ >=20419 & date_<=20423
display date("2016-04-30", "YMD")
replace conventiondate = 1  if date_ >=20573 & date_<=20577
display date("2017-04-22", "YMD")
replace conventiondate = 1  if date_ >=20930 & date_<=20934
display date("2017-12-02", "YMD")
replace conventiondate = 1  if date_ >=21154 & date_<=21158
display date("2018-06-30", "YMD")
replace conventiondate = 1  if date_ >=21364 & date_<=21368
display date("2019-11-30", "YMD")
replace conventiondate = 1  if date_ >=21882 & date_<=21886

* year dummies

gen y2013 = 0
replace y2013=1 if Year==2013
gen y2014 = 0
replace y2014=1 if Year==2014
gen y2015 = 0
replace y2015=1 if Year==2015
gen y2016 = 0
replace y2016=1 if Year==2016
gen y2017 = 0
replace y2017=1 if Year==2017
gen y2018 = 0
replace y2018=1 if Year==2018
gen y2019 = 0
replace y2019=1 if Year==2019


drop if year<2015



* explaining the focus on migrants in afd press releases


gen views_Eurokrise_t = views_Eurokrise[_n-1]/100
gen views_Eurokrise_t7 = views_Eurokrise[_n-7]/100

gen views_trend_t = views_trend[_n-1]/100
gen views_trend_t7 = views_trend[_n-7]/100

gen views_Fluchtling_t = views_Fluchtling[_n-1]/100
gen views_Fluchtling_t7 = views_Fluchtling[_n-7]/100



*rename V1 Financial_policy
replace Financial_policy=0 if Financial_policy==.

*rename V3 Eurozone_Greece
replace Eurozone_Greece=0 if Eurozone_Greece==.

*rename V4 EU, Merkel, Refugees
replace EU_Merkel_refugees=0 if EU_Merkel_refugees==.

*rename V15 Refugees_Borders
replace Refugees_borders=0 if Refugees_borders==.

exit



***Analysis

* Table 1: one day time lag
eststo clear
eststo: fracreg probit EU_Merkel_refugees views_Fluchtling_t conventiondate postelectiondate y2016 y2017 y2018 y2019 views_trend_t

eststo: fracreg probit Refugees_borders views_Fluchtling_t conventiondate postelectiondate y2016 y2017 y2018 y2019 views_trend_t

eststo: fracreg probit Financial_policy views_Eurokrise_t conventiondate postelectiondate y2016 y2017 y2018 y2019 views_trend_t

eststo: fracreg probit Eurozone_Greece views_Eurokrise_t conventiondate *postelectiondate y2016 y2017 y2018 y2019 views_trend_t




esttab using "PATH\results_onedaytimelag_08Jun2022.rtf" , replace ///
	abs b(3) se(3) ///
	star(+ 0.10 * 0.05 ** 0.01) ///
	aic ///
	scalars("ll Log pseudolikelihood") ///
	nonumbers /// 
	coeflabels(_cons "Constant" ///
	views_Terrorismus_t "Number of hits for the 'Terrorism' entry, one day before publication of press release" ///
views_Terrorismus_t7 "Number of hits for the 'Terrorism' entry, one week before publication of press release" ///
	views_Fluchtling_t "Number of hits for the 'Refugee' entry, one day before publication of press release" ///
views_Fluchtling_t7 "Number of hits for the 'Refugee' entry, one week before publication of press release" ///
views_Eurokrise_t7 "Number of hits for the 'Euro crisis' entry, one week before publication of press release" ///
views_Eurokrise_t "Number of hits for the 'Euro crisis' entry, one day before publication of press release" ///
views_Europaisches_Parlament_t7 "Number of hits for the 'European Parliament' entry, one week before publication of press release" ///
views_Europaisches_Parlament_t "Number of hits for the 'European Parliament' entry, one week before publication of press release" ///
	conventiondate "Time period of AfD party convention" ///
	postelectiondate "Time period after a federal or state election" ///
	views_trend_t "Number of hits for entries in the German Wikipedia, one day before publication of press release" ///
	views_trend_t7 "Number of hits for entries in the German Wikipedia, one week before publication of press release" ///
	y2016 "2016" ///
	y2017 "2017" ///
	y2018 "2018" ///
	y2019 "2019") ///
	nonotes addnotes("Note: Significance levels: + = p ≤ 0.1; * = p ≤ 0.05; ** = p ≤ 0.01.")



* Table 2: one week time lag
eststo clear

eststo: fracreg probit EU_Merkel_refugees views_Fluchtling_t7 conventiondate postelectiondate y2016 y2017 y2018 y2019 views_trend_t7

eststo: fracreg probit Refugees_borders views_Fluchtling_t7 conventiondate postelectiondate y2016 y2017 y2018 y2019 views_trend_t7

eststo: fracreg probit Financial_policy views_Eurokrise_t7 conventiondate postelectiondate y2016 y2017 y2018 y2019 views_trend_t7

eststo: fracreg probit Eurozone_Greece views_Eurokrise_t7 conventiondate *postelectiondate y2016 y2017 y2018 y2019 views_trend_t7






esttab using "PATH\results_oneweektimelag_08Jun2022.rtf" , replace ///
	abs b(3) se(3) ///
	star(+ 0.10 * 0.05 ** 0.01) ///
	aic ///
	scalars("ll Log pseudolikelihood") ///
	nonumbers /// 
	coeflabels(_cons "Constant" ///
	views_Terrorismus_t "Number of hits for the 'Terrorism' entry, one day before publication of press release" ///
views_Terrorismus_t7 "Number of hits for the 'Terrorism' entry, one week before publication of press release" ///
	views_Fluchtling_t "Number of hits for the 'Refugee' entry, one day before publication of press release" ///
views_Fluchtling_t7 "Number of hits for the 'Refugee' entry, one week before publication of press release" ///
views_Eurokrise_t7 "Number of hits for the 'Euro crisis' entry, one week before publication of press release" ///
views_Eurokrise_t "Number of hits for the 'Euro crisis' entry, one day before publication of press release" ///
views_Europaisches_Parlament_t7 "Number of hits for the 'European Parliament' entry, one week before publication of press release" ///
views_Europaisches_Parlament_t "Number of hits for the 'European Parliament' entry, one week before publication of press release" ///
	conventiondate "Time period of AfD party convention" ///
	postelectiondate "Time period after a federal or state election" ///
	views_trend_t "Number of hits for entries in the German Wikipedia, one day before publication of press release" ///
	views_trend_t7 "Number of hits for entries in the German Wikipedia, one week before publication of press release" ///
	y2016 "2016" ///
	y2017 "2017" ///
	y2018 "2018" ///
	y2019 "2019") ///
	nonotes addnotes("Note: Significance levels: + = p ≤ 0.1; * = p ≤ 0.05; ** = p ≤ 0.01.")